package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.CheckInfoService;
import com.itheima.service.OrderService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/checkinfoApp")
public class CheckInfoAppController {
    @Reference
    private CheckInfoService checkInfoService;



    @RequestMapping("/findByorderIdApp")
    public Result findByOrderId(Integer orderId){
        Map order = checkInfoService.findByorderId(orderId);
        return new Result(true,"预约订单查询成功",order);
    };
    @RequestMapping("/findAllCheckgroupAndCheckitemApp")
    public Result findAllCheckgroupAndCheckitem(Integer orderId){
        List<Map> list=null;
        List<Map<String, Object>> checkgroupList = checkInfoService.findAllCheckgroupAndCheckitem(orderId);
        list = new ArrayList<>();
        for (Map<String, Object> checkgroup : checkgroupList) {
            List<Map> checkitemList = (List<Map>) checkgroup.get("checkitemMap");
            for (Map checkitem : checkitemList) {
                Map map1 = new HashMap();
                map1.put("checkgroupName",checkgroup.get("checkgroupName").toString());
                map1.put("checkitemName",checkitem.get("checkitemName").toString());
                if(checkitem.get("content")!=null){
                    map1.put("content",checkitem.get("content").toString());
                }else{
                    map1.put("content","");
                }
                list.add(map1);
            }
        }
        return new Result(true,"查询检查组和检查项及内容信息成功",list);
    }


}
